#ifndef DS16XXDRIVER_H_
#define DS16XXDRIVER_H_

/************************************************************************************
*	Copyright Paxs Electronics 2012													*
*   All Rights Reserved																*
*   The Copyright symbol does not also indicate public availability or publication.	*
* 																					*
* 								PAXS ELECTRONICS									*
* 																					*
* - Driver:   			DS16XX Sensors.												*
* 																					*
* - Compiler:           Code Composer Studio (Licensed)								*
* - Supported devices:  All Stellaris Family Cortex-M3.								*
* - AppNote:																		*
*																					*
* 	Created by: 		Juan Francisco Gomez Ruiz									*
*   Date Created: 		6 - MAR - 2012												*
*   Contac				pacoduz@gmail.com											*
* 																					*
* 	Description: 		Driver for Temperature Sensor DS16XX Series.				*										*
*   Device supported and tested: - LM3S5749 - LM3S3748 -							*
* 																				2012*
*************************************************************************************

*************************************************************************************
* 	Revision History:
*
*   Date          CP#           Author
*   MM-DD-YY      XXXXX:1       Initials   Description of change
*   -----------   -----------   --------   ------------------------------------
*    03-06-12      	1.0             JFGR	Initial version. 
* 
*************************************************************************************
*
* File/
*  DS16XX Series Temperature Sensor Driver.
*  "Hardware abstraction Layer - First level".
* 
*  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 
*  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
*  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
*  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,  
*  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
*  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
*  DEALINGS IN THE SOFTWARE.
* 
*/

	#include "lm3s5749.h"
	#include "inc/hw_types.h"
	#include "driverlib/sysctl.h"
	#include "inc/hw_i2c.h"
	#include "driverlib/i2c.h"
	#include "inc/hw_memmap.h"
	#include "driverlib/gpio.h"

/******************************************************************************
*   						MACRO DEFINITIONS
******************************************************************************/	
	//////////////////////////////
	//	 	I2C MODULE			//		
	//////////////////////////////
	#define I2C0   			0
	#define I2C1			1
	#define I2C_MODULE_TS	(I2C1)		// Here is the Port that will handle the Temperature Sensor.
	#define I2C_400K		4			// *NOTE: I2C0 handle the 9DOF sensor stick
	#define I2C_100K		1
	#define I2C_FREQ		(I2C_400K)
	
	//////////////////////////////////////////////////
	//	DS1624XX SENSOR REGISTERS ADDRESS & VALUES	//
	//////////////////////////////////////////////////
	#define DS16XX_ADDRESS		0x48	//7-Bits I2C address
	#define ACCESS_CONFIG		0xAC
	#define READ_TEMPERATURE	0xAA
	#define START_CONVERT_T		0xEE
	#define STOP_CONVERT_T		0x22
	#define ACCESS_MEMORY		0x17
	#define ONE_SHOT_MODE		0
	#define CONTINUOUS_MODE		1

/******************************************************************************
*   Type Definitions
******************************************************************************/	
	typedef struct						//Structure to handle State Machin, that controls:
	{									// Reading and Writting of Temperature Sensor.			 
		unsigned char ActualState;
		unsigned char NextState;
	}SMts;
	
/******************************************************************************
*   						EXTERNAL VARIABLES
******************************************************************************/
				// TEMPERATURE SENSOR OUTPUT //
	//////////////////////////////////////////////////////
	typedef struct
	{
		char WholeTemperature;
		char DecimalTemperature;
	}DS16XXTemp;
	extern DS16XXTemp DS1624Temp;
	
	
/******************************************************************************
*   					GLOBAL FUNCTION PROTOTYPES
******************************************************************************/
	// Function to setup I2C module and Temperature Chip operation mode //
	void VfnDS16XXSensorInitialization(char Mode);
	// Fucntion than handle the State MAchine to read the Temperature 	//
	char VfnDS16XXSensorDriver(char Mode);
	// Function that return the Temperature onto a string	//
	// ** String must be a 9 lenght array					//
	void VfnDS16XXTemperatureToString(char* String,DS16XXTemp Temperature);


#endif /*DS16XXDRIVER_H_*/
